package com.hcc.gateway.common.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

import java.lang.reflect.Type;

/**
 * JsonUtils
 *
 * @author shengjun.hu
 * @date 2021/12/27
 */
public class JsonUtils {

    private static final ObjectMapper objectMapper = new ObjectMapper();

    private JsonUtils() {}

    @SneakyThrows
    public static String writeValueAsString(Object obj) {
        return objectMapper.writeValueAsString(obj);
    }

    @SneakyThrows
    public static <T> T readValue(String json, Class<T> clazz) {
        return objectMapper.readValue(json, clazz);
    }

}
